Crate fasthash

Source
Expand description

A suite of non-cryptographic hash functions for Rust.

§Example

use std::hash::{Hash, Hasher};

use fasthash::{metro, MetroHasher};

fn hash<T: Hash>(t: &T) -> u64 {
    let mut s: MetroHasher = Default::default();
    t.hash(&mut s);
    s.finish()
}

let h = metro::hash64(b"hello world\xff");

assert_eq!(h, hash(&"hello world"));

By default, HashMap uses a hashing algorithm selected to provide resistance against HashDoS attacks. The hashing algorithm can be replaced on a per-HashMap basis using the HashMap::with_hasher or HashMap::with_capacity_and_hasher methods.

It also cowork with HashMap or HashSet, act as a hash function

use std::collections::HashSet;

use fasthash::spooky::Hash128;

let mut set = HashSet::with_hasher(Hash128);
set.insert(2);

Or use RandomState<CityHash64> with a random seed.

use std::collections::HashMap;

use fasthash::{city, RandomState};

let s = RandomState::<city::Hash64>::new();
let mut map = HashMap::with_hasher(s);

assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.is_empty(), false);

map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");

Re-exports§

Modules§

  • CityHash, a family of hash functions for strings.
  • FarmHash, a family of hash functions.
  • Lookup3, non-cryptographic hash.
  • MetroHash, Exceptionally fast and statistically robust hash functions
  • MumHash, Hashing functions and PRNGs based on them
  • Murmur, a suite of non-cryptographic hash functions that was used for hash-based lookups.
  • Murmur2, a suite of non-cryptographic hash functions that was used for hash-based lookups.
  • Murmur3, a suite of non-cryptographic hash functions that was used for hash-based lookups.
  • SeaHash: A bizarrely fast hash function.
  • SpookyHash: a 128-bit noncryptographic hash function
  • Fast Positive Hash, aka “Позитивный Хэш”
  • xxHash - Extremely fast hash algorithm

Structs§

  • RandomState provides the default state for HashMap or HashSet types.
  • Generate hash seeds

Traits§

  • Hasher in the buffer mode for short key
  • Fast non-cryptographic hash functions
  • Fast non-cryptographic hasher
  • Generate a good, portable, forever-fixed hash value
  • A trait which represents the ability to hash an arbitrary stream of bytes.
  • Hasher in the streaming mode without buffer